fix: migrate open file handles to new mock on rename#346
Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: migrate open file handles to new mock on rename#346toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
After rename(), open filehandles lost access to data because each handle's weak 'data' reference still pointed to the old mock (whose contents was set to undef). This violated Unix semantics where open fds follow the inode, not the directory entry. The fix re-points each handle's data weakref and file path to the new mock during rename, matching real filesystem behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Open filehandles survive
rename()and continue reading/writing the file data at its new path.Why
After
rename('/old', '/new'), any filehandle opened on/oldlost access to the data. The tiedFileHandle's weakdataref still pointed to the old mock object (whosecontentswas set toundef), causing reads to return EOF and writes to produce uninitialized-value warnings. This violated Unix semantics where open fds follow the inode.How
During
__rename, after transferring contents from old mock to new mock, iterate over$mock_old->{'fhs'}and re-point each handle'sdataweakref andfilepath to the new mock. Thefhstracking array is also migrated.Testing
New
t/rename_open_handle.twith 5 subtests covering: read after rename, write after rename, tell preservation, multiple handles, and eof behavior. Full suite passes (1591 tests, pre-existingfh-ref-leak.tfailure only).🤖 Generated with Claude Code